﻿using System;
using System.Collections.Generic;
using NetBay.Core.BusinessEntities;

namespace Rio.Framework.Pages.Helpers.Comparer
{
    /// <summary>
    /// Custom comparer for the User class
    /// </summary>
    public class UserComparer : IEqualityComparer<User>
    {
        //Check whether the compared objects reference the same data.
        bool IEqualityComparer<User>.Equals(User x, User y)
        {
            //Check whether the compared objects reference the same data.
            if (Object.ReferenceEquals(x, y)) return true;

            //Check whether any of the compared objects is null.
            if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null))
                return false;

            //Check whether the products' properties are equal.
            return x.UserId == y.UserId;
        }

        int IEqualityComparer<User>.GetHashCode(User obj)
        {
            //Check whether the object is null
            if (Object.ReferenceEquals(obj, null)) return 0;

            //Get hash code for the UserId field
            int hashUserIdentifier = obj.UserId.GetHashCode();

            //Get hash code for the Code field.
            int hashUserCode = obj.UserId.GetHashCode();

            //Calculate the hash code for the product.
            return hashUserIdentifier ^ hashUserCode;

        }
    }
}
